package cn.exrick.xboot.base.serviceimpl

import cn.exrick.xboot.base.entity.ExamPassEmployee
import cn.exrick.xboot.base.mapper.ExamPassEmployeeMapper
import cn.exrick.xboot.base.service.IEmployeeOfficialExamRecordService
import cn.exrick.xboot.base.service.IEnterpriseUserService
import cn.exrick.xboot.base.service.IExamPassEmployeeService
import cn.exrick.xboot.core.common.utils.PageUtil
import cn.exrick.xboot.core.common.utils.ResultUtil
import cn.exrick.xboot.core.common.utils.SecurityUtil
import cn.exrick.xboot.core.common.utils.ToolUtil
import cn.exrick.xboot.core.common.vo.PageVo
import cn.exrick.xboot.core.common.vo.Result
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.google.common.collect.Maps
import lombok.extern.slf4j.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

/**
 * 考试通过人员接口实现
 * @author Fei
 */
@Slf4j
@Service
@Transactional
open class IExamPassEmployeeServiceImpl : ServiceImpl<ExamPassEmployeeMapper?, ExamPassEmployee?>(), IExamPassEmployeeService {


    @Autowired
    private lateinit var iEmployeeOfficialExamRecordService: IEmployeeOfficialExamRecordService

    @Autowired
    private lateinit var securityUtil: SecurityUtil

    @Autowired
    private lateinit var iEnterpriseUserService: IEnterpriseUserService

    override fun getExamPassEmployeeList(pageVo: PageVo): Result<MutableMap<String, Any?>?>? {

       return ToolUtil.setListToNul(list(KtQueryWrapper(ExamPassEmployee::class.java)
                .eq(ExamPassEmployee::enterpriseId, iEnterpriseUserService.getEnterpriseIdByEmployeeUserId(securityUtil.currUser.id))
                .orderByDesc(ExamPassEmployee::createTime)))?.run {

            val result: MutableMap<String, Any?> = Maps.newHashMap()
            result["size"] = size
            result["content"] = PageUtil.listToPage(pageVo, mapNotNull { iEmployeeOfficialExamRecordService.getEmployeeOfficialExamVo(it?.officialExamRecordId!!) })

            ResultUtil.data(result, "获取成功")
        } ?: ResultUtil.error(201, "暂无数据")
    }

}